import rx.Observable;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * Created by codeczx on 2017/2/22.
 */
public class TimeShiftedTest {

    void testBuffer() {
        Observable.interval(100, TimeUnit.MILLISECONDS)
                .take(10)
                .buffer(Observable.interval(250, TimeUnit.MILLISECONDS))
                .subscribe(System.out::println);
    }

    void testBuffer1(){
        Observable.interval(100,TimeUnit.MILLISECONDS)
                .take(10)
                .buffer(200,TimeUnit.MILLISECONDS)
                .subscribe(System.out::println);
    }

    void testDelay() {
        Observable.interval(100, TimeUnit.MILLISECONDS).take(5)
                .delay(i -> Observable.timer(i * 100, TimeUnit.MILLISECONDS))
                .timeInterval()
                .subscribe(System.out::println);
    }

    void testDebounce() {
        Observable.concat(
                Observable.interval(100, TimeUnit.MILLISECONDS).take(3),
                Observable.interval(500, TimeUnit.MILLISECONDS).take(3),
                Observable.interval(100, TimeUnit.MILLISECONDS).take(3)
        )
                .scan(0,(acc,v)->acc+1)
//                .timeInterval()
//                .debounce(150, TimeUnit.MILLISECONDS)
                .subscribe(System.out::println);
    }

    public static void main(String[] args) {
        TimeShiftedTest tst = new TimeShiftedTest();
//        tst.testBuffer();
//        tst.testDelay();
//        tst.testDebounce();
        tst.testBuffer1();
        try {
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
